﻿using System;
using System.IO;
using FFmpegVideoClip.Lib;
using PropertyChanged;

namespace FFmpegVideoClip.Mode.Files
{
    [AddINotifyPropertyChangedInterface]
    public class FileInfo : IDeepCopy<FileInfo>
    {
        public TimeSpan TimeDuration { get; private set; } = TimeSpan.Zero;
        public string TimeDurationShow => $"[{Tools.GetTimeSpanToString_RoundSeconds(TimeDuration)}]";
        public bool IsVideoStream { get; init; } = false;
        public bool IsAudioStream { get; init; } = false;
        public bool IsSubStream { get; init; } = false;
        public string Name { get; set; } = string.Empty;
        public string FullName { get; set; } = string.Empty;
        public string FullPath { get; set; } = string.Empty;
        public string Extension { get; set; } = string.Empty;
        public int Width { get; private set; }
        public int Height { get; private set; }
        public string Width_Height_String => Width < 1 || Height < 1 ? string.Empty : $"{Width}×{Height}";
        public bool IsExists => File.Exists(FullPath);
        public string Directory => Path.GetDirectoryName(FullPath) ?? string.Empty;
        public CompletionStatusEnum CompletionStatus { get; set; } = CompletionStatusEnum.NotStart;
        public FileInfo(string FullPath, TimeSpan? timeDuration = null, bool IsVideoStream = false, bool IsAudioStream = false, bool IsSubStream = false,int Width = 0,int Height = 0)
        {
            if (timeDuration == null)
            {
                var info=GetMediaInfo.GetInfo(FullPath);
                TimeDuration = info.Duration;
                Width = info.Width; Height=info.Height;
            }
            else { TimeDuration = timeDuration.Value; this.Width = Width; this.Height = Height; }
            this.IsVideoStream = IsVideoStream;
            this.IsAudioStream = IsAudioStream;
            this.IsSubStream = IsSubStream;
            this.FullPath = FullPath;
            Extension = Path.GetExtension(FullPath);
            Name = Path.GetFileNameWithoutExtension(FullPath);
            FullName=Path.GetFileName(FullPath);
        }
        FileInfo IDeepCopy<FileInfo>.DeepCopy()
        {
            throw new System.NotImplementedException();
        }
    }
}
